﻿@{
    ViewBag.Title = "故障明细";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="~/Areas/Dev/ViewModels/Dev.com.js"></script>
    <script src="~/Areas/Dev/ViewModels/Dev.viewModel.edit.js"></script>
    <script type="text/javascript">
            using(['numberbox','lookup','combobox']);
            var viewModel = function(){
                var self = this;
                Dev.viewModel.edit.apply(self,arguments);
                this.grid.size={w:6,h:151};
                this.saveClick = function () {
                    //存名称
                    var mc = $('#Gzjl_Fxry').combobox('getText')
                    self.form["Gzjl_Fxry"] =mc;
                    var gzyy = $('#Gzjl_Fxry').combobox('getText')
                    self.form["Gzjl_Fxry"] =gzyy;
                    var zryy = $('#Gzjl_Gzzry').combobox('getText')
                    self.form["Gzjl_Gzzry"] =zryy;
                    //保存主表及明细表
                    if (self.readonly()) return;
                    self.gridEdit.ended(); //结束grid编辑状态
                    var post = {           //传递到后台的数据
                        form: com.formChanges(self.form, data.form, self.setting.postFormKeys),
                        list: self.gridEdit.getChanges(self.setting.postListFields)
                    };
                    if ((self.gridEdit.ended() && com.formValidate()) && (post.form._changed || post.list._changed)) {
                        com.ajax({
                            url: self.urls.edit,
                            data: ko.toJSON(post),
                            success: function (d) {
                                com.message('success', self.resx.editSuccess);
                                ko.mapping.fromJS(post.form, {}, data.form); //更新旧值
                                self.gridEdit.accept();
                            }
                        });
                    }

                    };
                this.addRowClick = function(){
                        if (self.readonly()) return;
                        var sBillNo = this.scrollKeys.current();
                        //获取RowId 与单据编号
                        com.ajax({
                            type: 'GET',
                            url: this.urls.getrowid + 1,
                            data: { BillNo: sBillNo },
                            success: function (d) {
                                var row = $.extend({ Gzjlmx_BillNo: sBillNo, Gzjlmx_Flbh: d }, self.defaultRow);
                                self.gridEdit.addnew(row);
                            }
                        });

              };  

              this.grid.OnBeforeDestroyEditor = function (editors, row) {
                    row.Gzjlmx_Yyms = editors["Gzjlmx_Yyms"].target.lookup('textbox').val();
                    row.Gzjlmx_Fzry = editors["Gzjlmx_Fzry"].target.lookup('textbox').val();
                    row.Gzjlmx_Jcry = editors["Gzjlmx_Jcry"].target.lookup('textbox').val();
                    
              };
              this.grid.OnAfterCreateEditor = function(editors,row){

                     function clearIframe(context) {
                        var frame = $('iframe', context);
                        if (frame.length > 0) {
                            frame[0].contentWindow.document.write('');
                            frame[0].contentWindow.close();
                            frame.remove();
                            if ($.browser.msie) {
                                CollectGarbage();
                            }
                        }
                    }

                    var target = parent.$('#selectWlzd').length ? parent.$('#selectWlzd') : parent.$('<div id="selectWlzd"></div>').appendTo('body');
                    var iInput = editors["Gzjlmx_Yyms"].target;
                    var onShowPanel = function () {
                        iInput.lookup('hidePanel');
                        var parm = self.form.Gzjl_Sbbh();
                        target.data("lookup", { lookupType: 'sbgzyy',parentField:'pid',valueTitle: '编码', textTitle: '名称',remarkTitle:'备注',queryParams:{}}).window({
                            title: '&nbsp;故障原因'
                            , width: 600
                            , height: 420
                            , iconCls: 'icon-flag_france'
                            , modal: true
                            , collapsible: false
                            , minimizable: false
                            , maximizable: true
                            , closable: true
                            , content: "<iframe id='frm_win_project' src='/plugins/lookup?r=" + Math.random() + "' style='height:100%;width:100%;border:0;' frameborder='0'></iframe>" //frameborder="0" for ie7
                            , onClose: function () {
                                var rtnValue = target.data("returnValue");
                                if (rtnValue) {
                                    iInput.lookup('setValue',rtnValue.text);
                                    iInput.lookup('setText',rtnValue.text);
                                }
                                clearIframe(target);
                                target.window('destroy');
                            }
                        });
                };
                iInput.lookup({ customShowPanel: false, onShowPanel: onShowPanel, editable: true });
                iInput.lookup('resize', iInput.parent().width());
                iInput.lookup('textbox').unbind();
            };
    };
    var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
    ko.bindingViewModel(new viewModel(data));
    </script>
}
 <div class="z-toolbar">
        <a id="a_save" href="#" plain="true" class="easyui-linkbutton" icon="icon-save" data-bind="click:saveClick,linkbuttonDisable:readonly" title="保存">保存</a>
        <a id="a_undo" href="#" plain="true" class="easyui-linkbutton" icon="icon-undo" data-bind="click:rejectClick,linkbuttonDisable:readonly" title="撤消">撤消</a>
        <a id="a_audit" href="#" plain="true" class="easyui-linkbutton" icon="icon-user-accept" data-bind="click:auditClick,easyuiLinkbutton:approveButton" title="审核">审核</a>
        <a id="a_printer" href="#" plain="true" class="easyui-linkbutton" icon="icon-printer" title="打印" data-bind="click:printClick">打印</a>
        <div class="datagrid-btn-separator"></div>
        <a id="a_first" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_first" data-bind="click:firstClick,linkbuttonEnable:scrollKeys.firstEnable" title="第一条"></a> 
        <a id="a_previous" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_previous" data-bind="click:previousClick,linkbuttonEnable:scrollKeys.previousEnable" title="上一条"></a> 
        <a id="a_next" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_next" data-bind="click:nextClick,linkbuttonEnable:scrollKeys.nextEnable" title="下一条"></a> 
        <a id="a_last" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_last" data-bind="click:lastClick,linkbuttonEnable:scrollKeys.lastEnable" title="最后一条"></a> 
    </div>

    <div id="master" class="container_12" data-bind="inputwidth:0.9">
        <div class="grid_1 lbl">单据编号</div>
        <div class="grid_3 val"><input type="text" id="Gzjl_BillNo" name="Gzjl_BillNo"  data-bind="value:form.Gzjl_BillNo,readOnly:true" class="z-txt readonly"/></div>
        <div class="grid_1 lbl required">设备名称</div>
        <div class="grid_3 val"><input type="text"  data-bind="lookupValue:form.Gzjl_Sbbh,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sbda',multiple:false"/></div>
        <div class="grid_1 lbl">业务日期</div>
        <div class="grid_3 val"><input type="text" id="Gzjl_Ywrq" name="Gzjl_Ywrq" data-bind="dateboxValue:form.Gzjl_Ywrq,dateboxReadOnly:readonly" class="z-txt easyui-datebox" /></div> 
        <div class="clear"></div> 
               
        <div class="grid_1 lbl required">发现人员 </div>
        <div class="grid_3 val required"><input type="text" id ="Gzjl_Fxry" data-bind="lookupValue:form.Gzjl_Fxry,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sysuser',multiple:false"/></div>
        <div class="grid_1 lbl">故障描述</div>
        <div class="grid_3 val required"><input type="text" data-bind="value:form.Gzjl_Gzms,readOnly:readonly" class="z-txt"  /></div>
        <div class="grid_1 lbl required">责任人员 </div>
        <div class="grid_3 val "><input type="text" id="Gzjl_Gzzry" data-bind="lookupValue:form.Gzjl_Gzzry,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sysuser',multiple:false"  /></div>
        <div class="clear"></div>

        <div class="grid_1 lbl required">故障原因</div>
        <div class="grid_3 val "><input type="text" id="Gzjl_Gzyy" data-bind="lookupValue:form.Gzjl_Gzyy,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sbgzyy',multiple:false"  /></div>
        <div class="grid_1 lbl required">是否维修 </div>
        <div class="grid_3 val "><input type="text" data-bind="comboboxValue:form.Gzjl_Sfwx" data-options="data: data.dataSource.iswx, editable: false" class="z-txt easyui-combobox"  /></div>
        <div class="grid_1 lbl required">是否改善 </div>
        <div class="grid_3 val "><input type="text" data-bind="comboboxValue:form.Gzjl_Sfgs" data-options="data: data.dataSource.iswx, editable: false"  class="z-txt easyui-combobox"  /></div>
         <div class="clear"></div>

        <div class="grid_1 lbl">备注说明 </div>
        <div class="grid_3 val required"><input type="text" data-bind="value:form.Gzjl_Remark,readOnly:readonly" class="z-txt"  /></div>

        <div class="clear"></div>
    </div>
  
    <div id="tt" class="easyui-tabs">  
        <div title="表单明细">
            <table id="list" data-bind="datagrid:grid">
                <thead>
                    <tr>
                        <th field="Gzjlmx_BillNo" hidden="true">单据编号</th>  
                        <th field="Gzjlmx_Flbh"   hidden= "true"  align="left"    width="150" editor="{type:'validatebox',options:{required:true}}"  >分录编号</th> 
                        <th field="Gzjlmx_Yyms"     align="left"    width="150" editor="{type:'lookup'}"  >故障原因 </th>  
                        <th field="Gzjlmx_Fzry"     align="left"    width="80"  editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >负责人员   </th>  
                        <th field="Gzjlmx_Gscs"     align="left"    width="150"   editor="text" >改善措施   </th>  
                        <th field="Gzjlmx_Csms"     align="left"    width="200"   editor="text" >措施描述   </th>
                        <th field="Gzjlmx_Jcry"     align="left"    width="80" editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >检查人员   </th> 
                        <th field="Gzjlmx_Remark"       sortable="true" align="center"  width="200" editor="text"  >备注说明</th> 
                        <th field="CreatePerson"        sortable="true" align="center"  width="70"   >创建人</th>  
                        <th field="CreateDate"          sortable="true" align="center"  formatter="com.formatDate"    width="100" >创建日期</th>   
                    </tr>
                </thead>
            </table>  
            
            <div id="gridtb">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" data-bind="click:addRowClick,linkbuttonDisable:readonly">增加明细</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" data-bind="click:removeRowClick,linkbuttonDisable:readonly">删除明细</a>
            </div>  
        </div>
        <div title="表单信息" class="hide" style="padding-top:2px;">
            <div class="container_12" id="BillDetail" data-bind="inputwidth:0.9,autoheight:181"> 
                <div class="clear"></div>
                <div class="grid_1 lbl">审批状态</div>
                <div class="grid_3 val"><input type="text" id="ApproveState" data-bind="value:form.ApproveState,readOnly:true" class="z-txt readonly"/></div>
                <div class="grid_1 lbl">审批意见</div>
                <div class="grid_3 val"><input type="text" id="ApproveRemark" data-bind="value:form.ApproveRemark,readOnly:true"  class="z-txt readonly"/></div>
                <div class="grid_1 lbl">审批人 </div>
                <div class="grid_3 val"><input type="text" id="ApprovePerson"data-bind="value:form.ApprovePerson,readOnly:true" class="z-txt readonly"/></div>

                <div class="clear"></div>
                <div class="grid_1 lbl">审批日期</div>
                <div class="grid_3 val"><input type="text" id="ApproveDate" data-bind="dateboxValue:form.ApproveDate,dateboxReadOnly:true"  class="z-txt easyui-datebox readonly"/></div>
                <div class="grid_1 lbl">编制日期</div>
                <div class="grid_3 val"><input type="text" id="CreateDate" data-bind="dateboxValue:form.CreateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
                <div class="grid_1 lbl">编制人</div>
                <div class="grid_3 val "><input type="text" id="CreatePerson" data-bind="value:form.CreatePerson,readOnly:true" class="z-txt readonly" /></div>
                
                <div class="clear"></div>
                <div class="grid_1 lbl">修改日期</div>
                <div class="grid_3 val"><input type="text" id="UpdateDate" data-bind="dateboxValue:form.UpdateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
                <div class="grid_1 lbl">修改人</div>
                <div class="grid_3 val "><input type="text" id="UpdatePerson" data-bind="value:form.UpdatePerson,readOnly:true" class="z-txt readonly" /></div>
            </div>
        </div> 
    </div>  
